package com.bosi.message.impl.test;

import com.bosi.message.impl.RedisMessageService;
import io.lettuce.core.RedisClient;

import java.util.HashMap;

public class RedisMessageServiceConsumer0 {


    public static void main(String[] args) throws InterruptedException {
        RedisClient client = RedisConfig.getRedisClient();
        String game = "youyu";

        RedisMessageService messageService = new RedisMessageService(client, game);

        //订阅

         //系统消息
        //世界消息
        //房间消息
        //私人消息
        subscribeSys(messageService);
        subscribeWorld(messageService);
        subscribeRoom(messageService);
        subscribeUser(messageService);

        Thread.sleep(1000000);
    }

    private static void subscribeSys(RedisMessageService messageService) {
        HashMap<String, Object> header = new HashMap<>();
        //管理员消息
        header.put("tag", "sys");
        String uuid = messageService.subscribe(header, message -> System.out.println("[系统消息]" + message));
        System.out.println("订阅系统消息:" + uuid);
    }

    private static void subscribeWorld(RedisMessageService messageService) {
        HashMap<String, Object> header = new HashMap<>();
        header.put("tag", "world");
        String uuid = messageService.subscribe(header, message -> System.out.println("[世界消息]" + message));
        System.out.println("订阅世界消息:" + uuid);

    }

    private static void subscribeRoom(RedisMessageService messageService) {
        HashMap<String, Object> header = new HashMap<>();
        header.put("room", "000001");
        String uuid = messageService.subscribe(header, message -> System.out.println("[房间消息]" + message));
        System.out.println("订阅房间消息:" + uuid);

    }

    private static void subscribeUser(RedisMessageService messageService) {
        HashMap<String, Object> header = new HashMap<>();
        header.put("user", "u-001");
        String uuid = messageService.subscribe(header, message -> System.out.println("[私人消息]" + message));
        System.out.println("订阅私人消息:" + uuid);

    }
}
